package com.example.controller.shopping;

import com.example.common.Result;
import com.example.model.entity.shopping.MedicinesStyle;
import com.example.model.vo.MedicinesStyleVO;
import com.example.service.shopping.MedicinesStyleService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 药品规格表前端操作接口
 **/
@RestController
@RequestMapping("/medicinesStyle")
@Api(tags = "药品规格接口")
public class MedicinesStyleController {

    @Resource
    private MedicinesStyleService medicinesStyleService;

    /**
     * 新增
     */
    @ApiOperation(value = "新增药品规格")
    @PostMapping("/add")
    public Result add(@RequestBody MedicinesStyle medicinesStyle) {
        medicinesStyleService.add(medicinesStyle);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除药品规格")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        medicinesStyleService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除药品规格")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        medicinesStyleService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改药品规格")
    @PutMapping("/update")
    public Result updateById(@RequestBody MedicinesStyle medicinesStyle) {
        medicinesStyleService.updateById(medicinesStyle);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询药品规格")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        MedicinesStyle medicinesStyle = medicinesStyleService.selectById(id);
        return Result.success(medicinesStyle);
    }

    /**
     * 查询所有
     */    @ApiOperation(value = "查询所有药品规格")
    @GetMapping("/selectAll")
    public Result selectAll(MedicinesStyle medicinesStyle) {
        List<MedicinesStyleVO> list = medicinesStyleService.selectAll(medicinesStyle);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询药品规格")
    @GetMapping("/selectPage")
    public Result selectPage(MedicinesStyle medicinesStyle,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<MedicinesStyleVO> page = medicinesStyleService.selectPage(medicinesStyle, pageNum, pageSize);
        return Result.success(page);
    }

}
